<template>
	<view class="like">

		<!-- 顶部文字 -->
		<view class="top">
			<view>
				<image class="icon" src="../../static/image/icon_cha.png">已收藏{{collectedFeastNumber}}个餐宴</image>
			</view>
			<view>
				<image class="icon" src="../../static/image/icon_clear.png">清空</image>
			</view>
		</view>

		<!-- 卡片列表 -->
		<view class="cardlist" v-for="feast in collectedFeast">

			<!-- 一个单独的卡片 -->
			<view class="card-item">
				<image class="image" :src="feast.img"></image>
				<!-- 图片下方文字 -->
				<view class="info">
					<!-- 左侧内容 -->
					<view class="content-left">
						<view class="title">
							{{feast.goodsname}}
						</view>
						<view class="price">
							${{feast.price}}/桌
						</view>
					</view>

					<!-- 右侧内容 -->
					<view class="content-left">
						<image class="icon" src="../../static/image/footer2-sel.png">
						</image>
						<view class="greyText" @click="cancelCollect(feast.id)">
							取消收藏
						</view>
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				collectedFeastNumber: 8,

				collectedFeast: [{
					"id":1,
						"img": "../../static/image/goods4.png",
						"goodsname": "麻辣小龙虾",
						"price": 88
					},
					{
						"id":2,
						"img": "../../static/image/goods1.jpg",
						"goodsname": "和牛拉面",
						"price": 28
					},
					{
						"id":3,
						"img": "../../static/image/goods3.jpg",
						"goodsname": "避风塘炒蟹",
						"price": 188
					},
					{
						"id":4,
						"img": "../../static/image/goods2.jpg",
						"goodsname": "法式罗宋汤",
						"price": 28
					}
				]
			}
		},
		methods: {
		cancelCollect(id){
			console.log(id,"1630")
			console.log(this,"1633")
			this.$data.collectedFeast.forEach((item,index)=>{
				if(index===id){
					console.log("index:",index,"id:",id)
					// 在数组里删除这个元素
					this.collectedFeast.splice(index,1)
				}
			})
			// this.$data.splice(id,1);
		}
		}
	}
</script>

<style lang="less">
	.top {
		display: flex;
		justify-content: space-between;
		padding: 0 30rpx;
		height: 50rpx;
	}

	.cardlist {
		.card-item {
			box-shadow: 3px 3px 10px #ccc;
			margin: 3px 3px 3px 3px;
			padding: 0rpx 30rpx;

			.image {
				width: 100%;
				height: 400rpx;
				border-radius: 20rpx;
			}

			.info {
				display: flex;
				justify-content: space-between;

				.content-left {
					.title {}

					.price {
						color: red;
					}
				}

				.content-right {
					.title {}

					.greyText {
						color: grey;
					}
				}
			}
		}
	}

	.icon {
		margin: -5rpx;
		height: 40rpx;
		width: 40rpx;
	}
</style>
